﻿
using System;
using System.Linq;
using Microsoft.SharePoint.WebPartPages;
using WebPart = System.Web.UI.WebControls.WebParts.WebPart;

namespace SharePoint.Orm.Helpers {
	public static class SPLimitedWebPartManagerHelper {
		public static TWebPart FindWebPartByTitle<TWebPart>(this SPLimitedWebPartManager wpm, string title) where TWebPart : WebPart {
			WebPart wp = wpm.WebParts.Cast<WebPart>()
				.FirstOrDefault(w => string.Equals(w.Title, title, StringComparison.InvariantCultureIgnoreCase));
			return (TWebPart)wp;
		}
	}
}
